|
ARD2
RC2
Airbag Reference Demonstrator using MPC5604P
|
00001 00018 #include "derivative.h" 00019 #include "Compile_Options.h" 00020 #include "ADC.h" 00021 #include "CRC.h" 00022 #include "DSPI.h" 00023 #include "EDMA.h" 00024 #include "FCU.h" 00025 #include "LIN_UART.h" 00026 #include "ME.h" 00027 #include "PIT.h" 00028 #include "SIU.h" 00029 #include "SWT.h" 00030 #include "HAL.h" 00031 #include "CGM.h" 00032 #include "CG147.h" 00033 #include "IntcInterrupts.h" /* Implement functions from this file */ 00034 #include "Exceptions.h" 00035 #include "Maildelivery.h" /* For postal service */ 00036 #include "MailScheduler.h" /* For postal service `scheduler */ 00037 #ifdef USE_FREEMASTER 00038 #include "Freemaster.h" 00039 #endif 00040 /* 00041 ****************************************************************************** 00042 * constants 00043 ****************************************************************************** 00044 */ 00046 static const SWTConfig_t tWatchDogConfig = 00047 { 00048 SWT_WINDOW_COUNTS(0x0000F000u), SWT_TIME_OUT_COUNTS(0x10000001u), 00049 (uint32_t)(SWT_DIS | SWT_DEBUG_DIS | SWT_STOP_DIS) 00050 //(uint32_t)(SWT_EN | SWT_DEBUG_EN | SWT_STOP_DIS | SWT_SOFT_LOCK_EN | \ 00051 // SWT_HARD_LOCK_DIS | SWT_WINDOWED_MODE_DIS | SWT_RESET_WHEN_INVALID | \ 00052 // SWT_RANDOM_KEY_DIS | SWT_USES_OSCILLATOR) 00053 }; 00054 00056 static const uint16_t 00057 au16PeripheralConfig[] = 00058 { 00059 /* Peripheric RUN Mode Low-Power */ 00060 /* Config for DSPI0 */ 00061 ((ME_DSPI0 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_ON 00062 | DEBUG_FREEZE_ON), 00063 /* Config for DSPI1 */ 00064 ((ME_DSPI1 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00065 | DEBUG_FREEZE_OFF), 00066 /* Config for DSPI2 */ 00067 ((ME_DSPI2 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00068 | DEBUG_FREEZE_OFF), 00069 /* Config for DSPI3 */ 00070 ((ME_DSPI3 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00071 | DEBUG_FREEZE_OFF), 00072 /* Config for CAN0 */ 00073 ((ME_FLEXCAN0 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00074 | DEBUG_FREEZE_OFF), 00075 /* Config for FLEXRAY0 */ 00076 ((ME_FLEXRAY0 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00077 | DEBUG_FREEZE_OFF), 00078 /* Config for Safety Port */ 00079 ((ME_SAFETYPORT << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00080 | DEBUG_FREEZE_OFF), 00081 /* Config for ADC0 */ 00082 ((ME_ADC0 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00083 | DEBUG_FREEZE_OFF), 00084 /* Config for ADC1 */ 00085 ((ME_ADC1 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00086 | DEBUG_FREEZE_OFF), 00087 /* Config for CTU0 */ 00088 ((ME_CTU0 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00089 | DEBUG_FREEZE_OFF), 00090 /* Config for ETIMER0 */ 00091 ((ME_ETIMER0 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00092 | DEBUG_FREEZE_OFF), 00093 /* Config for ETIMER1 */ 00094 ((ME_ETIMER1 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00095 | DEBUG_FREEZE_OFF), 00096 /* Config for PWM0 */ 00097 ((ME_PWM0 << BITS_IN_BYTE) | RUN_ALWAYS_OFF | LP_ALWAYS_OFF 00098 | DEBUG_FREEZE_OFF), 00099 /* Config for SCI0 */ 00100 ((ME_LINFLEX0 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_ON 00101 | DEBUG_FREEZE_OFF), 00102 /* Config for SCI1 */ 00103 ((ME_LINFLEX1 << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00104 | DEBUG_FREEZE_OFF), 00105 /* Config for PIT */ 00106 ((ME_PIT << BITS_IN_BYTE) | RUN_ALWAYS_ON | LP_ALWAYS_OFF 00107 | DEBUG_FREEZE_OFF) }; 00108 00110 static const ISRConfig_t tISRConfig[] = 00111 { 00112 /* ISR Vector Priority */ 00113 { 00114 vfnDSPI0EOQIsr, DSPI0_EOQF_INT, ISR_MED_PRIORITY }, 00115 { 00116 vfnDSPI0RFDFIsr, DSPI0_RFDF_INT, ISR_LOW_PRIORITY }, 00117 { 00118 vfnDSPI0TCFIsr, DSPI0_TCF_INT, ISR_VL_PRIORITY }, 00119 { 00120 vfnDSPI0TFFFIsr, DSPI0_TFFF_INT, ISR_VL_PRIORITY }, 00121 { 00122 vfnDSPI1RFDFIsr, DSPI1_RFDF_INT, ISR_LOW_PRIORITY }, 00123 { 00124 vfnDSPI1TCFIsr, DSPI1_TCF_INT, ISR_VL_PRIORITY }, 00125 { 00126 vfnDSPI1TFFFIsr, DSPI1_TFFF_INT, ISR_VL_PRIORITY }, 00127 // { 00128 // vfnADC0EoCIsr, ADC0_EOC_INT, ISR_UL_PRIORITY }, 00129 // { 00130 // vfnADC0EoCIsr, ADC0_EOC_INT, ISR_UL_PRIORITY }, 00131 // { 00132 // vfnADC0ErrIsr, ADC0_ER_INT, ISR_UL_PRIORITY }, 00133 // { 00134 // vfnADC0WatchDogIsr, ADC0_WD_INT, ISR_UL_PRIORITY }, 00135 // { 00136 // vfnADC1EoCIsr, ADC1_EOC_INT, ISR_UL_PRIORITY }, 00137 // { 00138 // vfnADC1ErrIsr, ADC1_ER_INT, ISR_UL_PRIORITY }, 00139 // { 00140 // vfnADC1WatchDogIsr, ADC1_WD_INT, ISR_UL_PRIORITY }, 00141 { 00142 vfnSchedIsr, PIT_CH0_INT, ISR_VH_PRIORITY }, 00143 { 00144 vfnCG147WD2Isr, SOFT_CONFIG_FLAG_4, ISR_MED_LO_PRIORITY }, 00145 { 00146 vfnReschedulerIsr, PIT_CH1_INT, ISR_HI_PRIORITY }, 00147 { 00148 vfnReScheduleWD, SOFT_CONFIG_FLAG_6, ISR_MED_PRIORITY }, 00149 { 00150 vfnReScheduleWD3, SOFT_CONFIG_FLAG_7, ISR_LOW_PRIORITY }, 00151 { 00152 vfnSchedInboxDoneIsr, DMA_12_INT, ISR_UH_PRIORITY }, 00153 { 00154 vfnSchedInboxDoneIsr, DMA_13_INT, ISR_UH_PRIORITY }, 00155 { 00156 vfnCRC0Isr, DMA_10_INT, ISR_MED_PRIORITY }, 00157 { 00158 vfnCRC1Isr, DMA_11_INT, ISR_MED_PRIORITY }, 00159 00160 #ifdef USE_FREEMASTER 00161 { 00162 FMSTR_Isr, LIN0_RXI_INT, ISR_MIN_PRIORITY }, 00163 { 00164 FMSTR_Isr, LIN0_TXI_INT, ISR_MIN_PRIORITY }, 00165 { 00166 FMSTR_Isr, LIN1_RXI_INT, ISR_MIN_PRIORITY }, 00167 { 00168 FMSTR_Isr, LIN1_TXI_INT, ISR_MIN_PRIORITY }, 00169 #else 00170 { 00171 vfnLIN0RxIsr, LIN0_RXI_INT, ISR_UL_PRIORITY}, 00172 { 00173 vfnLIN0TxIsr, LIN0_TXI_INT, ISR_MIN_PRIORITY}, 00174 { 00175 vfnLIN1RxIsr, LIN1_RXI_INT, ISR_UL_PRIORITY}, 00176 { 00177 vfnLIN1TxIsr, LIN1_TXI_INT, ISR_MIN_PRIORITY} 00178 #endif 00179 }; 00181 static const uint16_t cau16DefaultPinConfig[PIN_CONFIG_REGISTER_MAX] = 00182 { 00183 #ifdef USE_ARD2_V1 00184 PIN_ALT3_CONFIG, PIN_DISABLED, PIN_GPO_DEFAULT_CONFIG, /* 0 - 2: FCU0,-,EN_FL for the time being */ 00185 PIN_PROGRAM, PIN_PROGRAM, PIN_GPIO_DEFAULT_CONFIG, /* 3 - 5: -,-,CG_N_SYNC */ 00186 PIN_GPIO_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 6 - 8: -,DIS_AHP,DIS_ALP */ 00187 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 9 - 11 */ 00188 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 12 - 14 */ 00189 PIN_GPO_DEFAULT_CONFIG, PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, /* 15 - 17: CG_N_SYS_RES,DEBUG,- */ 00190 PIN_ALT1_CONFIG, (PIN_GPI_DEFAULT_CONFIG), PIN_ALT1_CONFIG, /* 18 - 20: LIN0, LIN0, TDO */ 00191 0x0107, PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 21 - 23: TDI, CLKOUT, LIN0 */ 00192 PIN_DISABLED, PIN_DISABLED, PIN_ANALOG_CONFIG, /* 24 - 26: -,-, CG147's AOUT */ 00193 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 27 - 29 */ 00194 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 30 - 32 */ 00195 PIN_DISABLED, PIN_DISABLED, PIN_ALT3_CONFIG, /* 33 - 35: -, -, LIN1 */ 00196 PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, /* 36 - 38: DSPI0 */ 00197 PIN_MISO_CONFIG, PIN_ALT3_CONFIG, PIN_DISABLED, /* 39 - 41: MISO0, CG_N_CS_MON, - */ 00198 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 42 - 44 */ 00199 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 45 - 47 */ 00200 PIN_GPO_DEFAULT_CONFIG, PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, /* 48 - 50: LED, LED, - */ 00201 PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, PIN_ALT1_CONFIG, /* 51 - 53: LED,-, CS3 */ 00202 PIN_ALT1_CONFIG, PIN_DISABLED, PIN_GPO_DEFAULT_CONFIG, /* 54 - 56: CS2, -,-, */ 00203 PIN_ALT2_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 57 - 59: LIN1,-,- */ 00204 PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 60 - 62: LIN1,-,- */ 00205 PIN_DISABLED, PIN_ANALOG_CONFIG, PIN_DISABLED, /* 63 - 65: -,-,- */ 00206 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 66 - 68: -, -,- */ 00207 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 69 - 71 */ 00208 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 72 - 74 */ 00209 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 75 - 77 */ 00210 PIN_DISABLED, PIN_DISABLED, PIN_GPO_DEFAULT_CONFIG, /* 78 - 80: -,-,DEBUG */ 00211 PIN_GPO_DEFAULT_CONFIG, PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, /* 81 - 83: DEBUG, DEBUG */ 00212 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 84 - 86 */ 00213 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 87 - 89 */ 00214 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 90 - 92 */ 00215 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 93 - 95 */ 00216 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 96 - 100*/ 00217 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 99 - 101*/ 00218 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 102- 104*/ 00219 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 105- 107*/ 00220 #endif 00221 #ifdef USE_ARD2_V2 00222 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_PROGRAM, /* 0 - 2: CAN_EN, CAN_STDBY, ABS0 */ 00223 PIN_PROGRAM, PIN_PROGRAM, PIN_GPIO_DEFAULT_CONFIG, /* 3 - 5: ABS2, FAB, N_SYNC */ 00224 PIN_GPIO_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 6 - 8: EN_FL, DIS_AHP, DIS_ALP */ 00225 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, /* 9 - 11 CFG1 LIN_ENABLE CFG2 */ 00226 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_DISABLED, /* 12 - 14 CFG3, CFG4, N_POR */ 00227 PIN_GPIO_DEFAULT_CONFIG, PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 15 - 17: CG_N_SYS_RES, MCU_CANTX_A, MCU_CANRX_A */ 00228 PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, /* 18 - 20: MCU_LINTX_A, MCU_LINRX_A1, NC */ 00229 PIN_DISABLED, PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 21 - 23: NC CLKOUT MCU_LINRX_A2 */ 00230 PIN_DISABLED, PIN_ANALOG_CONFIG, PIN_ANALOG_CONFIG, /* 24 - 26: TP MCU_AN11 AOUT */ 00231 PIN_ANALOG_CONFIG, PIN_ANALOG_CONFIG, PIN_ANALOG_CONFIG, /* 27 - 29 MCU_AN13, MCU_AN14, MCU_AN0 */ 00232 PIN_GPI_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, /* 30 - 32 ARM_X, ARM_Y, TP */ 00233 PIN_DISABLED, PIN_DISABLED, PIN_GPIO_DEFAULT_CONFIG, /* 33 - 35: TP, TP, RES_CONF */ 00234 PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, /* 36 - 38: DSPI0_NCS DSPI0_SCK DSPI0_MOSI */ 00235 PIN_MISO_CONFIG, PIN_ALT3_CONFIG, PIN_GPIO_DEFAULT_CONFIG, /* 39 - 41: DSPI0_MISO CG_N_CS_MON RESET_BGYRO */ 00236 PIN_GPIO_DEFAULT_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 42 - 44 RESET_FSLGYRO MCU_UART_RTS MCU_UART_CTS */ 00237 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 45 - 47 TP TP TP */ 00238 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, /* 48 - 50: LED1 LED2 LED3 */ 00239 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_ALT2_CONFIG, /* 51 - 53: LED4 LED5 MCU_FCU0 */ 00240 PIN_ALT1_CONFIG, PIN_ALT2_CONFIG, PIN_ALT3_CONFIG, /* 54 - 56: N_CSGYRO MCU_FCU1 N_CSACC */ 00241 PIN_ALT2_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 57 - 59: MCU_UART_TXD, TP TP */ 00242 PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 60 - 62: MCU_UART_RXD TP TP */ 00243 PIN_ANALOG_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 63 - 65: MCU_AN4 CAN_NERR TP */ 00244 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 66 - 68: TP NC NC */ 00245 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 69 - 71: NC NC NC */ 00246 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 72 - 74: NC NC NC */ 00247 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 75 - 77: NC NC NC */ 00248 PIN_DISABLED, PIN_DISABLED, PIN_GPO_DEFAULT_CONFIG, /* 78 - 80: NC, NCC ,144 Package from here on: DEBUG */ 00249 PIN_GPO_DEFAULT_CONFIG, PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, /* 81 - 83: DEBUG, DEBUG */ 00250 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 84 - 86 */ 00251 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 87 - 89 */ 00252 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 90 - 92 */ 00253 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 93 - 95 */ 00254 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 96 - 100*/ 00255 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 99 - 101*/ 00256 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 102- 104*/ 00257 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 105- 107*/ 00258 #endif 00259 #ifdef USE_ARD2_V3 00260 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_PROGRAM, /* 0 - 2: CAN_EN, CAN_STDBY, ABS0 */ 00261 PIN_PROGRAM, PIN_PROGRAM, PIN_GPIO_DEFAULT_CONFIG, /* 3 - 5: ABS2, FAB, N_SYNC */ 00262 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, /* 6 - 8: EN_FL, RES_CONF, RES_GYRO_FSL */ 00263 PIN_GPIO_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 9 - 11 RES_GYRO_B CFG1 CFG2 */ 00264 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 12 - 14 - - - */ 00265 PIN_GPIO_DEFAULT_CONFIG, PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, /* 15 - 17: CG_N_SYS_RES, MCU_CANTX_A, MCU_CANRX_A */ 00266 PIN_ALT1_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, /* 18 - 20: MCU_LINTX_A, MCU_LINRX_A, NC */ 00267 PIN_DISABLED, PIN_ALT1_CONFIG, PIN_DISABLED, /* 21 - 23: NC CLKOUT NC */ 00268 PIN_DISABLED, PIN_DISABLED, PIN_ANALOG_CONFIG, /* 24 - 26: NC NC AOUT */ 00269 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 27 - 29 NC, NC, NC */ 00270 PIN_GPI_DEFAULT_CONFIG, PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, /* 30 - 32 DIS_AHP, DIS_ALP, NC */ 00271 PIN_DISABLED, PIN_DISABLED, PIN_ALT1_CONFIG, /* 33 - 35: NC, NC, N_CS_GYRO_FSL */ 00272 PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, PIN_ALT1_CONFIG, /* 36 - 38: DSPI0_NCS DSPI0_SCK DSPI0_MOSI */ 00273 PIN_MISO_CONFIG, PIN_ALT3_CONFIG, PIN_DISABLED, /* 39 - 41: DSPI0_MISO CG_N_CS_MON NC */ 00274 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 42 - 44 NC NC NC */ 00275 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 45 - 47 NC NC NC */ 00276 PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, PIN_GPIO_DEFAULT_CONFIG, /* 48 - 50: LED1 LED2 LED3 */ 00277 PIN_GPIO_DEFAULT_CONFIG, PIN_DISABLED, PIN_ALT2_CONFIG, /* 51 - 53: LED4 NC MCU_FCU0 */ 00278 PIN_ALT1_CONFIG, PIN_ALT3_CONFIG, PIN_ALT3_CONFIG, /* 54 - 56: N_CSACC_B N_CS_GYRO_B N_CSACC_FSL */ 00279 PIN_ALT2_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 57 - 59: MCU_UART_TXD, NC NC */ 00280 PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, PIN_DISABLED, /* 60 - 62: MCU_UART_RXD NC NC */ 00281 PIN_DISABLED, PIN_GPI_DEFAULT_CONFIG, PIN_DISABLED, /* 63 - 65: NC CAN_NERR NC */ 00282 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 66 - 68: NC NC NC */ 00283 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 69 - 71: NC NC NC */ 00284 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 72 - 74: NC NC NC */ 00285 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 75 - 77: NC NC NC */ 00286 PIN_DISABLED, PIN_DISABLED, PIN_GPO_DEFAULT_CONFIG, /* 78 - 80: NC, NCC ,144 Package from here on: DEBUG */ 00287 PIN_GPO_DEFAULT_CONFIG, PIN_GPO_DEFAULT_CONFIG, PIN_DISABLED, /* 81 - 83: DEBUG, DEBUG */ 00288 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 84 - 86 */ 00289 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 87 - 89 */ 00290 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 90 - 92 */ 00291 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 93 - 95 */ 00292 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 96 - 100*/ 00293 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 99 - 101*/ 00294 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 102- 104*/ 00295 PIN_DISABLED, PIN_DISABLED, PIN_DISABLED, /* 105- 107*/ 00296 #endif 00297 }; 00298 00303 static const uint8_t cau8DefaultInputPadRouting[] = 00304 { 00305 /* Pad Mux Selection */ 00306 PAD_LIN1_RXD, PAD_SEL1, /* Route the input pad to D[12] */ 00307 PAD_LIN0_RXD, PAD_SEL0 /* Route the input pad to B[3] */ 00308 }; 00309 00314 static const uint8_t cau8DefaultOutputPinConfig[] = 00315 { 00316 /* Format is set by DefaultOutputPin_t */ 00317 PIN_EN_FL, CLEAR, /* Enable Squibs signal to SBC */ 00318 PIN_N_SYS_RES, TRUE, /* Reset pin to SBC */ 00319 PIN_DSPI0_MISO, TRUE /* DSPI0 MISO - pull-up for others */ 00320 }; 00321 00325 static const uint32_t 00326 cau32DefaultDSPIPresetConfig[] = 00327 { 00328 /* 16-bit 8MHz w 64MHz PLL, 100nsec from CS low to CLK - CG147 */ 00329 (DSPI_CPOL_CLEAR | DSPI_CPHA_SET | DSPI_MSB_FIRST | DSPI_16_BIT 00330 | DSPI_DBR_CLEAR | DSPI_BRP_0 | DSPI_BR_1 | DSPI0C4 | DSPI_CCSCK_0 00331 | DSPI_PCSSCK_10), (DSPI_DT_1 | DSPI_PDT_10 | DSPI_PASC_10 00332 | DSPI_ASC_0), 00333 00334 /* 16-bit 5.3MHz w 64MHz PLL, 100nsec from CS low to CLK - MMA6800 */ 00335 (DSPI_CPOL_CLEAR | DSPI_CPHA_CLEAR | DSPI_MSB_FIRST | DSPI_16_BIT 00336 | DSPI_DBR_CLEAR | DSPI_BRP_0 | DSPI_BR_2 | DSPI0C5 | DSPI_CCSCK_0 00337 | DSPI_PCSSCK_01), (DSPI_DT_2 | DSPI_PDT_10 | DSPI_PASC_01 00338 | DSPI_ASC_0), 00339 /* 17-bit 8MHz w 64MHz PLL, 100nsec from CS low to CLK - CG147 */ 00340 /* Part 1*/ 00341 (DSPI_CPOL_CLEAR | DSPI_CPHA_SET | DSPI_MSB_FIRST | DSPI_8_BIT 00342 | DSPI_DBR_CLEAR | DSPI_BRP_0 | DSPI_BR_2 | DSPI0C6 | DSPI_CCSCK_0 00343 | DSPI_PCSSCK_10), (DSPI_DT_0 | DSPI_PDT_00 | DSPI_PASC_10 00344 | DSPI_ASC_0), 00345 /* 17-bit 8MHz w 64MHz PLL, 100nsec from CS low to CLK - CG147 */ 00346 /* Part 2*/ 00347 (DSPI_CPOL_CLEAR | DSPI_CPHA_SET | DSPI_MSB_FIRST | DSPI_9_BIT 00348 | DSPI_DBR_CLEAR | DSPI_BRP_0 | DSPI_BR_2 | DSPI0C7 | DSPI_CCSCK_0 00349 | DSPI_PCSSCK_10), (DSPI_DT_1 | DSPI_PDT_10 | DSPI_PASC_10 00350 | DSPI_ASC_0) }; 00351 00353 static const uint32_t 00354 cau32DefaultDSPIConfig[] = 00355 { 00356 /* DSPI0 */ 00357 (DSPI_ENABLE | DSPI_IS_MASTER | DSPI_CONT_CLK_DIS | DSPI_TX_FIFO_EN 00358 | DSPI_RX_FIFO_EN | DSPI_TX_ISR_EN | DSPI_TX_DMA_DIS | DSPI_RX_ISR_EN 00359 | DSPI_RX_DMA_DIS | DSPI_CS0_INVERT_EN | DSPI_CS1_INVERT_EN 00360 | DSPI_CS2_INVERT_EN | DSPI_CS3_INVERT_EN | DSPI_CS4_INVERT_EN 00361 | DSPI_CS5_INVERT_EN | DSPI_CS6_INVERT_EN | DSPI_CS7_INVERT_EN 00362 | DSPI_MODIFIED_TIME_DIS | DSPI0C0), 00363 00364 /* Others */ 00365 (DSPI_DISABLE | DSPI1C0), (DSPI_DISABLE | DSPI2C0), (DSPI_DISABLE 00366 | DSPI3C0) }; 00367 00369 static const uint8_t cau8DMAMuxConfig[] = 00370 { 00371 /* Order specifies channel. We start with Ch0 */ 00372 (DMA_MUX_ENABLED | DMA_TRIGGER_ENABLED | DMA_SOURCE_DSPI0_TX), /* CH0 */ 00373 (DMA_MUX_ENABLED | DMA_TRIGGER_DISABLED | DMA_SOURCE_DSPI0_RX), /* CH1 */ 00374 (DMA_MUX_ENABLED | DMA_TRIGGER_DISABLED | DMA_SOURCE_ADC0), /* CH2 */ 00375 (DMA_MUX_ENABLED | DMA_TRIGGER_DISABLED | DMA_SOURCE_ETIMER0_CH0), /* CH3 */ 00376 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI1_TX), /* CH4 */ 00377 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI1_RX), /* CH5 */ 00378 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI2_TX), /* CH6 */ 00379 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI2_RX), /* CH7 */ 00380 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI3_TX), /* CH8 */ 00381 (DMA_MUX_ENABLED | DMA_SOURCE_DSPI3_RX), /* CH9 */ 00382 (DMA_MUX_ENABLED | DMA_SOURCE_ETIMER0_CH1), /* CH10 */ 00383 (DMA_MUX_ENABLED | DMA_SOURCE_ETIMER1_CH0), /* CH11 */ 00384 (DMA_MUX_ENABLED | DMA_SOURCE_ETIMER1_CH1), /* CH12 */ 00385 (DMA_MUX_ENABLED | DMA_SOURCE_ALWAYS), /* CH13 */ 00386 (DMA_MUX_ENABLED | DMA_SOURCE_ALWAYS), /* CH14 */ 00387 (DMA_MUX_ENABLED | DMA_SOURCE_ALWAYS), /* CH15 */ 00388 }; 00389 00393 static const uint32_t cau32DefaultLINUARTConfig[] = 00394 { 00395 #ifdef USE_GENERIC_EVB_BOARD 00396 #ifdef USE_FREEMASTER 00397 /* Config for 56,200bps @ 64MHz */ 00398 (LIN_INSTANCE_0 | LIN_UART_ENABLED | LIN_TX_BUFF_1_BYTES 00399 | LIN_RX_BUFF_1_BYTES | LIN_NO_PARITY_CHECK | LIN_8_BIT_WORD_SIZE 00400 | LIN_MANTISSA(69) | LIN_FRACTION(7)), 00401 #else 00402 /* Config for 927,200bps @ 64MHz */ 00403 (LIN_INSTANCE_0 | LIN_UART_ENABLED | LIN_TX_BUFF_1_BYTES 00404 | LIN_RX_BUFF_1_BYTES | LIN_NO_PARITY_CHECK | LIN_8_BIT_WORD_SIZE 00405 | LIN_MANTISSA(4) | LIN_FRACTION(5)) 00406 #endif 00407 #else 00408 #ifdef USE_FREEMASTER 00409 /* Config for 57,600bps @ 64MHz */ 00410 (LIN_INSTANCE_1 | LIN_UART_ENABLED | LIN_TX_BUFF_1_BYTES 00411 | LIN_RX_BUFF_1_BYTES | LIN_NO_PARITY_CHECK | LIN_8_BIT_WORD_SIZE 00412 | LIN_MANTISSA(69) | LIN_FRACTION(7)), 00413 #else 00414 /* Config for 927,200bps @ 64MHz */ 00415 (LIN_INSTANCE_1 | LIN_UART_ENABLED | LIN_TX_BUFF_1_BYTES 00416 | LIN_RX_BUFF_4_BYTES | LIN_NO_PARITY_CHECK | LIN_8_BIT_WORD_SIZE 00417 | LIN_MANTISSA(4) | LIN_FRACTION(5)) 00418 #endif 00419 #endif 00420 }; 00421 00423 static const uint8_t cau8DefaultPLL0Config[] = 00424 { 00425 /* Config for only one instance */ 00426 PLL_INSTANCE_0, IDF_SETTING_FOR_64MHZ, ODF_SETTING_FOR_64MHZ, 00427 LDF_SETTING_FOR_64MHZ }; 00428 00430 static const uint8_t cau8DefaultPLL1Config[] = 00431 { 00432 /* Config for only one instance */ 00433 PLL_INSTANCE_1, IDF_SETTING_FOR_16MHZ, ODF_SETTING_FOR_16MHZ, 00434 LDF_SETTING_FOR_16MHZ }; 00435 00437 const uint32_t cau32ADCConfig[] = 00438 { 00439 /* Instance 0 - Continuous sampling every 17.75 usec */ 00440 (ADC_DATA_CAN_BE_OVERWRITTEN | ADC_DATA_IS_ALIGNED_RIGHT 00441 | ADC_IS_IN_SCAN_MODE | ADC_CTU_IS_OFF | ADC_AUTOCLOCK_OFF_EN 00442 | ADC_EO_CTU_CONV_ISR_DIS | ADC_EO_INJ_CHAN_CONV_ISR_DIS 00443 | ADC_EO_INJ_CHAIN_CONV_ISR_DIS | ADC_EO_CHAN_CONV_ISR_DIS 00444 | ADC_EO_CHAIN_CONV_ISR_DIS | ADC_DMA_CLEARED_ON_ACK | ADC_DMA_EN 00445 | ADC_IS_CLOCKING_HALF_SPEED | ADC_PR_LSB_NO_ROUNDING 00446 | ADC_LOW_SPEED_CONFIG), 00447 /* Instance 1 - Continuous sampling every 17.75 usec */ 00448 (ADC_DATA_CAN_BE_OVERWRITTEN | ADC_DATA_IS_ALIGNED_RIGHT 00449 | ADC_IS_IN_SCAN_MODE | ADC_CTU_IS_OFF | ADC_AUTOCLOCK_OFF_EN 00450 | ADC_EO_CTU_CONV_ISR_DIS | ADC_EO_INJ_CHAN_CONV_ISR_DIS 00451 | ADC_EO_INJ_CHAIN_CONV_ISR_DIS | ADC_EO_CHAN_CONV_ISR_DIS 00452 | ADC_EO_CHAIN_CONV_ISR_DIS | ADC_DMA_CLEARED_ON_ACK | ADC_DMA_DIS 00453 | ADC_IS_CLOCKING_HALF_SPEED | ADC_PR_LSB_NO_ROUNDING 00454 | ADC_LOW_SPEED_CONFIG) }; 00456 const uint32_t cau32FCUConfig[] = 00457 { 00458 /* Start with time-out */ 00459 FCU_TIMEOUT(FCU_4MS_TIMEOUT), 00460 /* Configure which software channels will allow a time-out, which */ 00461 /* SW channels are on, and which HW channels are on */ 00462 (FCU_TES0_ENABLED | FCU_TES1_ENABLED | FCU_TES2_ENABLED | FCU_TES3_ENABLED 00463 | FCU_TES4_ENABLED | FCU_ESF0_ENABLED | FCU_ESF1_ENABLED | FCU_ESF2_ENABLED 00464 | FCU_ESF3_ENABLED | FCU_ESF4_ENABLED | 00465 FCU_ENABLE_CH(FCU_CORE_CHECKSTOP_MODE_ENTERED | FCU_CORE_RESET | 00466 FCU_LOSS_OF_XTAL | FCU_LOSS_OF_PLL0_LOCK | 00467 FCU_FREQ0_OUT_OF_RANGE | FCU_LOSS_OF_PLL1_LOCK | 00468 FCU_FREQ1_OUT_OF_RANGE | FCU_FLASH_FATAL_ERROR | 00469 FCU_WATCHDOG_RESET | FCU_JTAG_RESET | FCU_POWER_COMPARATOR_ERROR 00470 | FCU_LVD_4_5 | FCU_LVD_2_7_VREG | FCU_LVD_2_7_FLASH | 00471 FCU_LVD_2_7_I_0 | FCU_LVD_1_2_DIG)), 00472 /* Configure which HW channels will accept a time-out */ 00473 (FCU_TIMEOUT_CH(FCU_CORE_CHECKSTOP_MODE_ENTERED | 00474 FCU_LOSS_OF_XTAL | FCU_LOSS_OF_PLL0_LOCK | 00475 FCU_FREQ0_OUT_OF_RANGE | FCU_LOSS_OF_PLL1_LOCK | 00476 FCU_FREQ1_OUT_OF_RANGE | FCU_FLASH_FATAL_ERROR | 00477 FCU_POWER_COMPARATOR_ERROR 00478 | FCU_LVD_4_5 | FCU_LVD_2_7_VREG | FCU_LVD_2_7_FLASH | 00479 FCU_LVD_2_7_I_0 | FCU_LVD_1_2_DIG) | FCU_NO_TEST_MODE | 00480 FCU_OUTPUT0_INV_POL | FCU_OUTPUT_IS_TIME_SWITCH | 00481 FCU_OUTPUT_FREQ(7u)) 00482 }; 00483 /* 00484 ****************************************************************************** 00485 * Globals 00486 ****************************************************************************** 00487 */ 00488 00489 /* 00490 ****************************************************************************** 00491 * u8fnMCUInit 00492 ****************************************************************************** 00493 */ 00494 uint8_t u8fnMCUInit(void) 00495 { 00496 uint8_t u8Status; 00497 uint16_t u16Counter; 00498 00499 u8Status = TRUE; 00500 00501 /* Launch Fault Collector Unit right away */ 00502 vfnLaunchFCU(); 00503 00504 /* Configure pins as they should be */ 00505 vfnConfigDefaultPinBehavior((uint16_t*)&cau16DefaultPinConfig, 0, 00506 PIN_CONFIG_REGISTER_MAX); 00507 00508 /* Configure default output pin levels */ 00509 vfnOutputPinInit(); 00510 00511 /* Route input pads to the correct modules */ 00512 vfnInputPadInit(); 00513 00514 /* Enable the appropriate interrupts in the system */ 00515 vfnInitInterrupts(); 00516 00517 /* Do the same with peripherals */ 00518 u8Status = u8fnInitPeripherals(); 00519 00520 if(CLEAR == u8Status) 00521 { 00522 /* Load Operation modes into the configuration register */ 00523 u8Status = u8fnInitDefaultOpModes(); 00524 if(CLEAR == u8Status) 00525 { 00526 /* Configure Watchdog */ 00527 u8Status = (uint8_t)u16fnConfigSoftwareWatchDog(&tWatchDogConfig); 00528 00529 if((SWT_SOFT_LOCKED == u8Status) || (SWT_UNLOCKED == u8Status)) 00530 { 00531 /* Configure the PLL for 64MHz operation */ 00532 00533 /* Then configure both PLLs */ 00534 u8Status = u8fnClockPLLConfig(cau8DefaultPLL0Config[CLEAR], 00535 cau8DefaultPLL0Config[1u], 00536 cau8DefaultPLL0Config[2u], 00537 cau8DefaultPLL0Config[3u]); 00538 u8Status |= u8fnClockPLLConfig(cau8DefaultPLL1Config[CLEAR], 00539 cau8DefaultPLL1Config[1u], 00540 cau8DefaultPLL1Config[2u], 00541 cau8DefaultPLL1Config[3u]); 00542 if(u8Status == CLEAR) 00543 { 00544 00545 /* Now jump to 64MHz operation */ 00546 for(u16Counter = CLEAR; u16Counter < 0x10; u16Counter++) 00547 { 00548 u8Status = u8fnSwitchOpModes(RUN3_MODE); 00549 if(u8Status) 00550 { 00551 vfnClockClearPLLFlag(PLL_INSTANCE_0); 00552 vfnClockClearPLLFlag(PLL_INSTANCE_1); 00553 } 00554 else 00555 { 00556 /* We're good */ 00557 break; 00558 } 00559 } 00560 /* If all is good, configure defaults for SPI, SCI */ 00561 if(CLEAR == u8Status) 00562 { 00563 vfnInitDSPI(); 00564 vfnInitSCI(); 00565 vfnInitADC(); 00566 EDMA.CR.B.ERCA = TRUE; 00567 } 00568 else 00569 { 00570 u8Status = RUN_MODE_NOT_STARTED; 00571 } 00572 } 00573 else 00574 { 00575 u8Status = PLL_ERROR; 00576 } 00577 } 00578 else 00579 { 00580 u8Status = SWT_NOT_INITIALIZED; 00581 } 00582 } 00583 else 00584 { 00585 u8Status = DEFAULT_OPERATION_MODES_NOT_LOADED; 00586 } 00587 } 00588 else 00589 { 00590 u8Status = PERIPHERALS_NOT_INITIALIZED; 00591 } 00592 00593 return (u8Status); 00594 } 00595 /* 00596 ****************************************************************************** 00597 * u8fnInitPeripherals 00598 ****************************************************************************** 00599 */ 00600 uint8_t u8fnInitPeripherals(void) 00601 { 00602 uint8_t u8Status; 00603 uint8_t u8PeripheralIndex; 00604 uint8_t u8PeripheralPreset; 00605 uint8_t u8Counter; 00606 00607 /* Initialize Peripherals */ 00608 /* First, we must tell the core what power-mode presets */ 00609 /* we are going to allow */ 00610 u8Status = u8fnInitDefaultPeripheralPresets(); 00611 00612 /* If all goes well, associate the given peripherals to a preset */ 00613 if(CLEAR == u8Status) 00614 { 00615 for(u8Counter = N_ELEMENTS(au16PeripheralConfig); u8Counter > CLEAR; u8Counter--) 00616 { 00617 u8PeripheralIndex = (uint8_t)(au16PeripheralConfig[u8Counter] 00618 >> BITS_IN_BYTE); 00619 u8PeripheralPreset = (uint8_t)(au16PeripheralConfig[u8Counter]); 00620 u8Status |= u8fnConfigPeripheralForMCUModePreset(u8PeripheralIndex, 00621 u8PeripheralPreset); 00622 } 00623 } 00624 else 00625 { 00626 /* Terminate - we need to figure out how to raise an exception */ 00627 } 00628 return (u8Status); 00629 } 00630 /* 00631 ****************************************************************************** 00632 * vfnInitInterrupts 00633 ****************************************************************************** 00634 */ 00635 void vfnInitInterrupts(void) 00636 { 00637 /* Declare local variables */ 00638 uint8_t u8Counter; 00639 00640 /* Init local variables */ 00641 u8Counter = CLEAR; 00642 00643 /* Configure the core (the IVOR) to its standard configuration where */ 00644 /* interrupts are handled by the INTC peripheral connected to IVOR 4. */ 00645 EXCEP_InitExceptionHandlers(); 00646 INTC_InitINTCInterrupts(); 00647 00648 /* First, set the INTC module's priority to the lowest setting */ 00649 /* This is necessary to allow other interrupts to occur */ 00650 INTC.CPR.B.PRI = ISR_INTC_PRIORITY; 00651 00652 /* Next, install all interrupts */ 00653 for(u8Counter = N_ELEMENTS(tISRConfig); u8Counter > CLEAR; u8Counter--) 00654 { 00655 INTC_InstallINTCInterruptHandler(tISRConfig[u8Counter - 1u].pFn, 00656 tISRConfig[u8Counter - 1u].u16ISRVector, 00657 tISRConfig[u8Counter - 1u].u8Priority); 00658 } 00659 00660 return; 00661 } 00662 /* 00663 ****************************************************************************** 00664 * vfnInitDSPI 00665 ****************************************************************************** 00666 */ 00667 void vfnInitDSPI(void) 00668 { 00669 /* Declare local variables */ 00670 uint8_t u8Counter; 00671 uint8_t u8MaxCount; 00672 00673 /* Init local variables */ 00674 u8Counter = CLEAR; 00675 00676 /* Configure DSPI instances, starting with their Presets */ 00677 if((N_DSPI_INSTANCES * N_DSPI_PRESETS) 00678 < (N_ELEMENTS(cau32DefaultDSPIPresetConfig) / 2u)) 00679 { 00680 u8MaxCount = (uint8_t)(N_DSPI_INSTANCES * N_DSPI_PRESETS); 00681 } 00682 else 00683 { 00684 u8MaxCount = (N_ELEMENTS(cau32DefaultDSPIPresetConfig)); 00685 } 00686 00687 for(u8Counter = CLEAR; u8Counter < u8MaxCount; u8Counter += 2u) 00688 { 00689 (void)u8fnConfigDSPIPreset( 00690 (const DSPIPresetConfig_t*)&(cau32DefaultDSPIPresetConfig[u8Counter])); 00691 } 00692 00693 /* Next, configure the general settings of all DSPI units */ 00694 if(N_DSPI_INSTANCES < N_ELEMENTS(cau32DefaultDSPIConfig)) 00695 { 00696 u8MaxCount = N_DSPI_INSTANCES; 00697 } 00698 else 00699 { 00700 u8MaxCount = N_ELEMENTS(cau32DefaultDSPIConfig); 00701 } 00702 for(u8Counter = CLEAR; u8Counter < u8MaxCount; u8Counter++) 00703 { 00704 (void)u8fnConfigDSPIGeneral((const DSPIConfig_t*) 00705 &(cau32DefaultDSPIConfig[u8Counter])); 00706 } 00707 return; 00708 } 00709 /* 00710 ****************************************************************************** 00711 * vfnInitADC 00712 ****************************************************************************** 00713 */ 00714 void vfnInitADC(void) 00715 { 00716 ADCChConfig_t tMyADCConfig; 00717 uint8_t u8Status; 00718 uint8_t u8Counter; 00719 uint16_t u16Dummy; 00720 u8Status = CLEAR; 00721 u8Counter = CLEAR; 00722 00723 /* Load main configuration - SCAN mode is a given */ 00724 for(; u8Counter < ADC_NO_MODULES; u8Counter++) 00725 { 00726 u8Status= u8fnADCConfig(u8Counter, 00727 (ADCConfig_t*)&(cau32ADCConfig[u8Counter])); 00728 } 00729 00730 /* Configure first instance (ADC0) for Aout readings */ 00731 tMyADCConfig.P.ChDMAEn = TRUE; 00732 tMyADCConfig.P.ChIsrEn = CLEAR; 00733 tMyADCConfig.P.Channel = ADC_TO_AOUT_CH; 00734 tMyADCConfig.P.DMACh = ADC0_DMA_CH; 00735 tMyADCConfig.P.Instance = 0u; 00736 00737 u8Status = u8fnADCChannelConfig((const ADCChConfig_t*)&tMyADCConfig, 00738 (uint16_t*)&u16Dummy); 00739 /* Gear-up! */ 00740 u8Status = u8fnADCNormalConversionEnable(0, TRUE); 00741 00742 return; 00743 } 00744 /* 00745 ****************************************************************************** 00746 * vfnInitSCI 00747 ****************************************************************************** 00748 */ 00749 void vfnInitSCI(void) 00750 { 00751 /* Declare local variables */ 00752 uint8_t u8Counter; 00753 uint8_t u8MaxCount; 00754 00755 /* Init local variables */ 00756 u8Counter = CLEAR; 00757 00758 /* Configure DSPI instances, starting with their Presets */ 00759 if(N_LIN_INSTANCES >= N_ELEMENTS(cau32DefaultLINUARTConfig)) 00760 { 00761 u8MaxCount = N_ELEMENTS(cau32DefaultLINUARTConfig); 00762 } 00763 else 00764 { 00765 u8MaxCount = (uint8_t)(N_LIN_INSTANCES); 00766 } 00767 00768 for(u8Counter = CLEAR; u8Counter < u8MaxCount; u8Counter++) 00769 { 00770 (void)u8fnConfigLINUARTGeneral((const LINUARTConfig_t*) 00771 &(cau32DefaultLINUARTConfig[u8Counter])); 00772 } 00773 00774 return; 00775 } 00776 /* 00777 ****************************************************************************** 00778 * vfnOutputPinInit 00779 ****************************************************************************** 00780 */ 00781 void vfnOutputPinInit(void) 00782 { 00783 uint8_t u8Counter; 00784 for(u8Counter = CLEAR; u8Counter < N_ELEMENTS(cau8DefaultOutputPinConfig); u8Counter 00785 += 3u) 00786 { 00787 vfnToggleOutputPin(cau8DefaultOutputPinConfig[u8Counter], 00788 cau8DefaultOutputPinConfig[u8Counter + 1u], 00789 cau8DefaultOutputPinConfig[u8Counter + 2u]); 00790 } 00791 return; 00792 } 00793 /* 00794 ****************************************************************************** 00795 * vfnInputPadInit 00796 ****************************************************************************** 00797 */ 00798 void vfnInputPadInit(void) 00799 { 00800 uint8_t u8Counter; 00801 for(u8Counter = CLEAR; u8Counter < N_ELEMENTS(cau8DefaultInputPadRouting); u8Counter 00802 += 2u) 00803 { 00804 (void)u8fnRouteInputPad(cau8DefaultInputPadRouting[u8Counter], 00805 cau8DefaultInputPadRouting[u8Counter + 1u]); 00806 } 00807 return; 00808 } 00809 /* 00810 ****************************************************************************** 00811 * u8fnInitDMAMux 00812 ****************************************************************************** 00813 */ 00814 void vfnInitDMAMux(uint8_t* pu8DMAMuxSettings, uint8_t u8Size) 00815 { 00816 /* Copy the DMA MUX configuration table into the right place */ 00817 for(; u8Size > CLEAR; u8Size--) 00818 { 00819 DMAMUX.CHCONFIG[u8Size - 1u].R = *pu8DMAMuxSettings; 00820 pu8DMAMuxSettings++; 00821 }; 00822 00823 return; 00824 } 00825 /* 00826 ****************************************************************************** 00827 * u8fnDelayMSec 00828 ****************************************************************************** 00829 */ 00830 uint8_t u8fnDelay(const uint32_t cu32TimeBase, uint16_t u16Cycles) 00831 { 00832 /* Declare local variables */ 00833 uint8_t u8Status; 00834 00835 /* Configure Channel */ 00836 u8Status = u8fnPITConfig(PIT_CH_DELAY, cu32TimeBase, CLEAR); 00837 00838 if(CLEAR == u8Status) 00839 { 00840 /* Start the counter */ 00841 vfnPITStart(PIT_CH_DELAY, TRUE); 00842 00843 /* Wait for if to expire */ 00844 for(; u16Cycles > CLEAR; u16Cycles--) 00845 { 00846 if(1u == u16Cycles) 00847 { 00848 /* If this is the last iteration, stop the counter */ 00849 u8Status |= u8fnPITWaitByPoll(PIT_CH_DELAY, CLEAR); 00850 } 00851 else 00852 { 00853 /* Else, restart the PIT counter as soon as we're done */ 00854 u8Status |= u8fnPITWaitByPoll(PIT_CH_DELAY, TRUE); 00855 } /* End ELSE */ 00856 } 00857 /* End FOR */ 00858 00859 if(CLEAR == u8Status) 00860 { 00861 /* Nothing, we're done */ 00862 } 00863 else 00864 { 00865 u8Status = PIT_TIMER_NOT_RUNNING; 00866 } 00867 } /* End If u8Status = CLEAR */ 00868 else 00869 { 00870 u8Status = PIT_SELECTED_CH_DOESNT_EXIST; 00871 } 00872 00873 return (u8Status); 00874 } 00875 /* 00876 ****************************************************************************** 00877 * u8fnRawADCToDegreesCelsius 00878 ****************************************************************************** 00879 */ 00880 uint8_t u8fnRawADCToDegreesCelsius(const uint16_t u16RawCounts) 00881 { 00882 int32_t i32Degrees; 00883 uint8_t u8Degrees; 00884 00885 /* Remove Offset */ 00886 i32Degrees = (int32_t)((ADC_TEMP_OFFSET_CTS) - u16RawCounts); 00887 i32Degrees *= ADC_SENSITIVITY; 00888 u8Degrees = (uint8_t)(40u + (i32Degrees / ADC_TEMP_SENSITIVITY_PER_DEG)); 00889 00890 return (u8Degrees); 00891 } 00892 /* 00893 ****************************************************************************** 00894 * u8fnRawADCToOutput 00895 ****************************************************************************** 00896 */ 00897 uint8_t u8fnRawADCToOutput(const uint16_t u16RawCounts) 00898 { 00899 int32_t i32Voltage; 00900 uint8_t u8Voltage; 00901 00902 i32Voltage = u16RawCounts * (ADC_SENSITIVITY); 00903 00904 u8Voltage = (uint8_t)(i32Voltage / 100000); 00905 00906 return (u8Voltage); 00907 } 00908 /* 00909 ****************************************************************************** 00910 * vfnLaunchFCU 00911 ****************************************************************************** 00912 */ 00913 void vfnLaunchFCU(void) 00914 { 00915 uint8_t u8Status; 00916 u8Status = u8fnFCUInit((FCUConfig_t*)&cau32FCUConfig); 00917 00918 if(CLEAR == u8Status) 00919 { 00920 (void)u8fnFCUEnableConfig(); 00921 } 00922 else 00923 { 00924 /* We're not doing anything */ 00925 } 00926 return; 00927 } 00928 /* 00929 ****************************************************************************** 00930 * u8fnInitPostalService 00931 ****************************************************************************** 00932 */ 00933 uint8_t u8fnInitPostalService(const uint8_t cu8Enable) 00934 { 00935 uint8_t u8Status; 00936 00937 u8Status = CLEAR; 00938 00939 if(CLEAR != cu8Enable) 00940 { 00941 /* First initialize both inbox and outboxes for DSPI. */ 00942 vfnMailboxInit(); 00943 00944 /* Followed by the init of both inbox and outboxes with the delivery system*/ 00945 /* Outbox will be used to send messages via the SPI using */ 00946 u8Status 00947 |= u8fnMailDeliveryOfOutboxInit( 00948 (uint32_t*)&(gau32DSPIOutbox[OUTBOX_ACTIVE_OUTBOX_IS_1]), 00949 (uint32_t*)&(DSPI_0.PUSHR), 00950 MAILDELIVERY_OUTBOX1_DMA_CH); 00951 u8Status 00952 |= u8fnMailDeliveryOfOutboxInit( 00953 (uint32_t*)&(gau32DSPIOutbox[OUTBOX_ACTIVE_OUTBOX_IS_2]), 00954 (uint32_t*)&(DSPI_0.PUSHR), 00955 MAILDELIVERY_OUTBOX2_DMA_CH); 00956 u8Status 00957 |= u8fnMailDeliveryToInboxInit((uint16_t*)((uint32_t)(&(DSPI_0.POPR)) 00958 + 2u)); 00959 00960 /* Configure DMA Mux so that it triggers every time we receive SPI data */ 00961 vfnDMAMUXInit(MAILDELIVERY_INBOX1_DMA_CH, DMA_SOURCE_DSPI0_RX, CLEAR, TRUE); 00962 00963 } 00964 else 00965 { 00966 /* Nothing to init really */ 00967 } 00968 00969 /* Switch to/from Interrupts depending on the value of u8Enable */ 00970 u8Status |= u8fnDSPISwitchIsrMode(DSPI0C0, cu8Enable); 00971 00972 return (u8Status); 00973 } 00974 /* 00975 ****************************************************************************** 00976 * u8fnLauchScheduler 00977 ****************************************************************************** 00978 */ 00979 uint8_t u8fnLaunchScheduler(const uint8_t cu8Enable) 00980 { 00981 uint8_t u8Status; 00982 00983 u8Status = u8fnSchedConfig(SCHED_TICK_PERIOD, PIT_SCHEDULING_CH, 00984 RESCHED_TICK_PERIOD, PIT_RESCHEDULE_CH); 00985 00986 if(CLEAR == u8Status) 00987 { 00988 (void)u8fnSchedEnable(cu8Enable); 00989 } 00990 else 00991 { 00992 /* Just go */ 00993 } 00994 00995 return (u8Status); 00996 } 00997 /* 00998 ****************************************************************************** 00999 * u8fnTransferADCResults 01000 ****************************************************************************** 01001 */ 01002 void vfnTransferADCResults(uint8_t u8Instance, uint16_t* pu16Destination, 01003 uint16_t u16Size) 01004 { 01005 TCD_t tMyDefaultConfig; 01006 01007 /* Program the dedicated EDMA channel for this operation */ 01008 01009 /* Source Address will always be the ADC result */ 01010 tMyDefaultConfig.P.SADDR = (((uint32_t)&ADC_0.CDR[ADC_TO_AOUT_CH].R) + 2u); 01011 /* Destination address is our output vehicle (DSPI, for example) */ 01012 tMyDefaultConfig.P.DADDR = (uint32_t)pu16Destination; 01013 /* Modulus is 0 */ 01014 tMyDefaultConfig.P.SMOD = CLEAR; 01015 tMyDefaultConfig.P.DMOD = CLEAR; 01016 /* We will transfer 32-bit words */ 01017 tMyDefaultConfig.P.SSIZE = DMA_SIZE_16_BIT; 01018 tMyDefaultConfig.P.DSIZE = DMA_SIZE_16_BIT; 01019 tMyDefaultConfig.P.SOFF = 0u; /* Offset per minor loop (in bytes) */ 01020 tMyDefaultConfig.P.DOFF = 2u; /* Destination offset per minor loop */ 01021 tMyDefaultConfig.P.NBYTES = 2u; /* Inner loop transfer count (in bytes) */ 01022 tMyDefaultConfig.P.SLAST = CLEAR; 01023 tMyDefaultConfig.P.CITERE_LINK = CLEAR; 01024 tMyDefaultConfig.P.BITERE_LINK = CLEAR; 01025 tMyDefaultConfig.P.CITER = u16Size; /* Times we'll execute our minor loop */ 01026 tMyDefaultConfig.P.BITER = u16Size; /* Memory for the loop */ 01027 tMyDefaultConfig.P.D_REQ = TRUE; /* Clear HW Start requests after major loop is done */ 01028 01029 tMyDefaultConfig.P.DLAST_SGA = -((int32_t)u16Size * 2u); /* Last destination offset */ 01030 tMyDefaultConfig.P.MAJORLINKCH = CLEAR; 01031 tMyDefaultConfig.P.BWC = DMA_BWC_4_CYCLE_STALL; 01032 tMyDefaultConfig.P.MAJORE_LINK = CLEAR; /* Disable ch2ch linking */ 01033 tMyDefaultConfig.P.E_SG = CLEAR; 01034 01035 tMyDefaultConfig.P.INT_HALF = CLEAR; 01036 tMyDefaultConfig.P.INT_MAJ = CLEAR; 01037 tMyDefaultConfig.P.START = CLEAR; 01038 01039 vfnDMAConfig(&tMyDefaultConfig, ADC0_DMA_CH + u8Instance); 01040 01041 /* Route it adequately */ 01042 vfnDMAMUXInit(ADC0_DMA_CH + u8Instance, DMA_SOURCE_ADC0 + u8Instance, 01043 CLEAR, TRUE); 01044 01045 /* Enable HW signaling to channel 8 (or 9) */ 01046 EDMA.SERQR.R = (uint8_t)ADC0_DMA_CH + u8Instance; 01047 01048 return; 01049 } 01050 /* 01051 ****************************************************************************** 01052 * vfnEnterLowPowerMode 01053 ****************************************************************************** 01054 */ 01055 void vfnEnterLowPowerMode(void) 01056 { 01057 (void)u8fnSwitchOpModes(STOP0_MODE); 01058 return; 01059 } 01060 /* 01061 ****************************************************************************** 01062 * vfnDefaultISR 01063 ****************************************************************************** 01064 */ 01065 static void vfnDefaultISR(void) 01066 { 01067 return; 01068 } 01069 /* 01070 ****************************************************************************** 01071 * 01072 * End of file. 01073 * 01074 ****************************************************************************** 01075 */